<?php
/**
 * @version 0.8.3 2010-10-07
 * @package Joomla
 * @subpackage LeagueResults
 * @copyright (C)  2008, 2009, 2010 Henryk Drozd
 * @license GNU/GPL, see LICENSE.php
 * LeagueResults is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License 2
 * as published by the Free Software Foundation.

 * LeagueResults is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');

jimport('joomla.application.component.model');

class lrModelTeam extends JModel
{
	var $_team = null;
	var $_id = null;
	
	function __construct()
	{
	parent::__construct();
	$id = JRequest::getVar ('id', 0);
	$this->_id = $id;
	$this->_sid = JRequest::getVar ('season', 0);
	}
	
	
	function getList()
	{
	if (!$this->_team)
		{
		$where = ($this->_sid==0?"":" AND s.id='".$this->_sid."' ");
		$query = "SELECT t.id, t.name AS teamname, t.tbadge, t.tablename AS teamshortname,
				t.description AS teamdescription, t.club_id AS club_id, tp.player_id,
				p.*, s.longname AS season, s.year AS syear
				FROM #__lr_teams AS t
				JOIN #__lr_teamplayers AS tp ON (t.id = tp.team_id)
				JOIN #__lr_players AS p ON (p.id = tp.player_id )
				JOIN #__lr_leagueseasons AS s ON (s.id = tp.leagueseasons_id)
				WHERE t.id = '".$this->_id."'".$where."
					AND t.published = 1
					AND tp.published = 1
					AND p.published = 1
					AND s.published = 1
				ORDER BY s.year DESC, p.lastname ASC";
									
				
		$this->_team = $this->_getList($query, 0, 0);
		}
	//echo $query;
	return $this->_team;
	}
}

?>